package com.zq.designpaterns.other.transferobject;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2021/01/28  16:00
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
public class StudentBO {
    private final List<StudentVO> studentVOS;

    public StudentBO() {
        studentVOS = new ArrayList<>();
        studentVOS.add(new StudentVO("jack", 1));
        studentVOS.add(new StudentVO("John", 2));
    }

    public void deleteStudent(StudentVO vo) {
        studentVOS.remove(vo);
        System.out.println("Student: Roll No " + vo.getRollNo() + ", deleted from database");
    }

    public List<StudentVO> getStudentAll() {
        return studentVOS;
    }

    public StudentVO getStudent(int rollNo) {
        for (StudentVO vo : studentVOS) {
            if (vo.getRollNo()==rollNo){
                return vo;
            }
        }
        return null;
    }

    public void updateStudent(StudentVO student) {
        studentVOS.get(student.getRollNo()).setName(student.getName());
        System.out.println("Student: Roll No "
                + student.getRollNo() +", updated in the database");
    }
}
